package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.dto.MyBedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    @PostMapping("/create")
/*    @ApiOperation(value = "添加床位", notes = "床位")
    public ResponseResult addBedInRoom(
            @ApiParam(value = "床位信息", required = true)
            @RequestBody MyBedDto myBedDto){

        return success();

    }*/
    @ApiOperation(value = "添加床位", notes = "床位")
    public ResponseResult addBedInRoom(
            @ApiParam(value = "床位信息", required = true)
            @RequestBody BedDto bedDto){
        int row=bedService.addBed(bedDto);
        return toAjax(row);

    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除床位", notes = "床位id")
    public ResponseResult removeBedById(
            @ApiParam(value = "床位Id", required = true)
            @PathVariable Integer id){
        int row = bedService.deleteById(id);
        return toAjax(row);
    }
    @GetMapping("/read/{bedId}")
    @ApiOperation(value = "根据床位id查询床位", notes = "床位id")
    @ApiImplicitParams(
            @ApiImplicitParam(name="bedId",value = "床位Id",dataType = "long")
    )
    public ResponseResult readBedById(@PathVariable("bedId") Long bedId) {
        BedVo vo =bedService.getById(bedId);
        return success(vo);
    }
    @PutMapping("/update")
    @ApiOperation(value = "根据床位id修改床位", notes = "床位信息")
    public ResponseResult updateById(
            @ApiParam(value = "床位信息", required = true)
            @RequestBody BedDto dto){
        int row=bedService.updateById(dto);
        return toAjax(row);
    }
}
